package com.wwx.worldonwheels.common.result;


import java.io.Serializable;
import java.util.Map;

/**
 * @description: 返回响应类
 * @params:
 * @return:
 * @author: 胡杨
 * @dateTime: 2022-01-22 18:15
 */

public class ResponseMessage<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    /** 状态码 0 表示成功，-1表示失败*/

    private Integer code;
    /** 数据*/
    private T data;
    /**
     * 描述
     */
    private String msg;

    public ResponseMessage() {
    }

    public ResponseMessage(Integer code, T data, String msg) {
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    /** 成功，传入数据
     *
     * @return
     */
    public static ResponseMessage buildSuccess() {
        return new ResponseMessage(0, null, null);
    }

    /**
     * 成功，传入数据
     */
    public static ResponseMessage buildSuccess(Object data) {
        return new ResponseMessage(0, data, null);
    }

    /** 成功，传入数据,及描述信息
     *
     * @param code
     * @param data
     * @param msg
     * @return
     */
    public static ResponseMessage buildSuccess(Integer code, Object data, String msg) {
        return new ResponseMessage(code, data, msg);
    }

    /**
     * // 失败，传入描述信息
     * @param msg
     * @return
     */
    public static ResponseMessage buildError(String msg) {
        return new ResponseMessage(-1, null, msg);
    }

    /**
     * // 失败，传入描述信息,状态码
     * @param msg
     * @param code
     * @return
     */
    public static ResponseMessage buildError(String msg, Integer code) {
        return new ResponseMessage(code, null, msg);
    }

    /**
     * // 失败，传入描述信息,状态码
     * @param code
     * @param map
     * @return
     */
    public static ResponseMessage buildError(Integer code, Map map) {
        return new ResponseMessage(code,map,null);
    }

    /**
     * set,get方法
     * @return
     */
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "JsonData [code=" + code + ", data=" + data + ", msg=" + msg
                + "]";
    }
}
